package cn.wolfcode.wolf2w.business.listen;

import cn.wolfcode.wolf2w.api.domain.Note;
import cn.wolfcode.wolf2w.api.domain.NoteSearch;
import cn.wolfcode.wolf2w.business.repository.NoteRepository;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浪兎兎
 * @since 2025-06-16 13:38
 */
@Component
public class NoteListener {
    @Autowired
    private NoteRepository noteRepository;
    @RabbitListener(queues = {"noteQueue"})
    public void onMessage(String message) {
        Note note = JSON.parseObject(message, Note.class);
        NoteSearch noteSearch = new NoteSearch();
        BeanUtils.copyProperties(note, noteSearch);
        noteRepository.save(noteSearch);
    }
}
